<extend name="Public:base" />
<block name="title">选择医院</block>
<block name="content">
    <input name="page" id="page" type="hidden" value="">
    <div class="weui-cell ">
        <div class=" sele_xial xuanzeyiyuan_sel ">
            <select class="weui-select " name="select2" id="select_province">
                        <option value="0">请选择</option>
                <foreach name="provincelist" item="vo">
                    <option value="{$vo['id']}">{$vo['name']}</option>
                </foreach>
            </select>
        </div>
        <div class=" sear_rxuanzyy">
            <input type="text" class=" input_border " id="searchname" placeholder="请输入医院名称">
        </div>
    </div>
    <div class="page__bd">
        <div class="page__bd" id="searchResult">
            <foreach name="hospitallist" item="list">
                <div class="weui-media-box weui-media-box_appmsg">
                    <div class="weui-media-box__hd sel_yiyuan_img">
                        <img class="weui-media-box__thumb huanzhe_toux " src="{$list['pic']}" alt="">
                    </div>
                    <div class="weui-media-box__bd">
                        <h4 class="weui-media-box__title">{$list['name']}</h4>
                        <div class="button-sp-area xinxi_but_area xuanze_yiyuan_but">
                            <a href="__MODULE__/Referral/hos_detail/id/{$list['id']}" class="weui-btn weui-btn_mini weui-btn_primary ">详情</a>
                            <a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_sel select_hos" data-id="{$list['id']}" data-name="{$list['name']}">选择</a>
                        </div>
                    </div>
                </div>
            </foreach>
        </div>
        <div id="msgshow">
        </div>
        <input type="button" id="more" class="listmore" value="加载更多">
    </div>
    <script type="text/javascript">
        $(function(){
            //默认选中选择的省份和医院名称
            var province_id = localStorage.getItem('province_id');
            var name        = localStorage.getItem('name');
            if(province_id){
                $('#select_province').val(JSON.parse(province_id));
            }
            if(name){
                $('#searchname').val(JSON.parse(name));
            }
            var page = 1;

            hos_list(name,province_id,page);
            //选择省份
            $("#select_province").change(function(){
                var province_id = $("#select_province option:selected").val();
                localStorage.setItem('province_id',JSON.stringify(province_id));
                $("#msgshow").html('');
                hos_list(name,province_id,page);
            });
            function hos_list(name,province_id,page){
                $.ajax({
                    type:'post',
                    url:'__MODULE__/Referral/hospitallist',
                    data:{name:JSON.parse(name),province_id:JSON.parse(province_id),page:page},
                    cache:false,
                    dataType:'json',
                    success:function(res){
                        if (res.code == 0) {
                            var arr = res.data;
                            var str = '';
                            $("#searchResult").html('');
                            $.each(arr, function (i) {
                                str += '<div class="weui-media-box weui-media-box_appmsg"><div class="weui-media-box__hd sel_yiyuan_img"><img class="weui-media-box__thumb huanzhe_toux " src="' + this.pic + '" alt=""> </div><div class="weui-media-box__bd"><h4 class="weui-media-box__title">' + this.name + '</h4><div class="button-sp-area xinxi_but_area xuanze_yiyuan_but"><a href="__MODULE__/Referral/hos_detail/id/' + this.id + '" class="weui-btn weui-btn_mini weui-btn_primary ">详情</a> <a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_sel select_hos" data-id="' + this.id +'" data-name="' + this.name +'">选择</a></div></div></div>';
                            });
                            $("#page").val(res.page);
                            $("#searchResult").append(str);
                        } else {
                            var str2 = '';
                            str2 += '<div class="nomore"><p>' + res.msg + '</p></div>';
                            $("#searchResult").html('');
                            $("#searchResult").html(str2);
                            $("#more").hide();
                        }
                    }
                });
            }
            //点击加载更多
            $("#more").click(function(){
                var page = $('#page').val();
                var province_id = $("#select_province option:selected").val();
                $.ajax({
                    type:'post',
                    url:'__MODULE__/Referral/hospitallist',
                    data:{name:JSON.parse(name),province_id:province_id,page:page},
                    cache:false,
                    dataType:'json',
                    success:function(res){
                        if (res.code == 0) {
                            var arr = res.data;
                            var str = '';
                            $.each(arr, function (i) {
                                str += '<div class="weui-media-box weui-media-box_appmsg"><div class="weui-media-box__hd sel_yiyuan_img"><img class="weui-media-box__thumb huanzhe_toux " src="' + this.pic + '" alt=""> </div><div class="weui-media-box__bd"><h4 class="weui-media-box__title">' + this.name + '</h4><div class="button-sp-area xinxi_but_area xuanze_yiyuan_but"><a href="__MODULE__/Referral/hos_detail/id/' + this.id + '" class="weui-btn weui-btn_mini weui-btn_primary ">详情</a> <a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_sel select_hos" data-id="' + this.id +'" data-name="' + this.name +'">选择</a></div></div></div>';
                            });
                            $("#page").val(res.page);
                            $("#searchResult").append(str);
                        } else {
                            var str2 = '';
                            str2 += '<div class="nomore"><p>' + res.msg + '</p></div>';
                            $("#msgshow").html(str2);
                            $("#more").hide();
                        }
                    }
                });
            });
            //变输入医院名称边搜索
            $(document).on('keyup','#searchname',function(){
                var name = $(this).val();
                localStorage.setItem('name',JSON.stringify(name));
                hos_list(name,province_id,page);
            });
            //选中医院并返回
            $(document).on('click',".select_hos",function(){
                var hos_id      = $(this).attr("data-id");
                var hos_name    = $(this).attr("data-name");
                var ob          = new Object();
                ob.hos_now_id   = hos_id;
                ob.hos_now_name = hos_name;
                localStorage.setItem('referral',JSON.stringify(ob));
                //referral = JSON.parse(localStorage.getItem('referral'));
                window.location.href = "__MODULE__/Referral/index";
            });
        });
    </script>
</block>